package com.zcc.makingfriend.service.impl;

import com.zcc.makingfriend.dao.Image;
import com.zcc.makingfriend.mapper.ImageMapper;
import com.zcc.makingfriend.service.AttachmentService;
import com.zcc.makingfriend.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * @author zcc
 */
@Service
public class ImageServiceImpl implements ImageService {
    @Autowired
    ImageMapper imageMapper;

    @Override
    public int addImage(Image image) {
        return imageMapper.addImage(image);
//        List<String> images = attachmentService.upload(files);
//        for (int i = 0; i < images.size(); i++) {
//            String imageFile = images.get(i);
//            Image image = new Image();
//            image.setArticleId(uuid);
//            image.setUrl(imageFile);
//            int j = imageMapper.addImage(image);
//            if (j == 0) {
//                return 0;
//            }
//        }
//        return 1;
    }

    @Override
    public int updateImage(Image image) {
        return imageMapper.updateImage(image);
//        List<String> images = attachmentService.upload(files);
//        for (int i = 0; i < images.size(); i++) {
//            String imageFile = images.get(i);
//            Image image = new Image();
//            image.setArticleId(uuid);
//            image.setUrl(imageFile);
//            int j = imageMapper.updateImage(image);
//            if (j == 0) {
//                return 0;
//            }
//        }
//        return 1;
    }

    @Override
    public List<Image> findImageByArticleId(String articleId) {
        List<Image> imageByArticleId = imageMapper.findImageByArticleId(articleId);
        return imageByArticleId;
    }
}
